package com.itheima.controller;

import com.itheima.manager.UserManager;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {

    @Autowired
    UserManager userManager;

    // 用户列表
    @GetMapping("/manage/users")
    public ResponseEntity findUserInfoByPage(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        return userManager.findUserInfoByPage(pageNum, pageSize);
    }

    // 用户详情
    @GetMapping("/manage/users/{userId}")
    public ResponseEntity findById(@PathVariable Long userId) {
        return userManager.findById(userId);
    }

    //动态列表
    @GetMapping("/manage/messages")
    public ResponseEntity findMovementByConditionAndPage(
            @RequestParam(value = "page",defaultValue = "1")Integer pageNum,
            @RequestParam(value = "pagesize",defaultValue = "10")Integer pageSize,
            @RequestParam(value = "uid",required = false)Long userId,
            @RequestParam(required = false)Integer state){
        return userManager.findMovementByConditionAndPage(userId,state,pageNum,pageSize);
    }

    // 单条动态详情
    @GetMapping("/manage/messages/{publishId}")
    public ResponseEntity findMovementById(@PathVariable ObjectId publishId){
        return userManager.findMovementById(publishId);
    }

    // 动态评论列表
    @GetMapping("/manage/messages/comments")
    public ResponseEntity findMovementComemntByPage(
            @RequestParam(value = "page",defaultValue = "1",required = false) Integer pageNum,
            @RequestParam(value = "pagesize",defaultValue = "10",required = false) Integer pageSize,
            @RequestParam(value = "messageID") String publishId){
        return userManager.findMovementComemntByPage(pageNum, pageSize, new ObjectId(publishId));
    }
}
